﻿#ifndef CSqlOper_H
#define CSqlOper_H
/********************************************************************************
** @ Date:2025/04/17
** @ Author: HanJiaXin
** @ Description:数据库语句
** @ Version:1.0.0
** @ ClassName:
** @ Fun:
********************************************************************************/
#include "Header.h"
#include "dbstruct.h"
class CDevDataBeltCorrect;
class CDevDataBeltRealign;
class CSqlOper
{
public:
	static CSqlOper& instance()
	{
		static CSqlOper instance;
		return instance;
	}

	bool initSql();
	bool addDefaultPoint(QString sPointGuid, QString sPointName, QString sBeltName, QString& sErrMsg);
	bool selectDevInfoName(const QString &sDevGuid, QVector<QSqlRecord>& vecRecord, QString &sErrMsg);
	bool selectCorrectInfo(const QString &sDevGuid, CDevDataBeltRealign* pDevData,QString &sErrMsg);
	bool selectCorrectResult(QString sPointName, QVector<QSqlRecord>& vecRecord, QString sStartTime, QString sEndTime, int nAlarm, QString& sErrMsg);
	bool selectCorrectData(QString sDevGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
	bool selectIoAllocationByID(CDevDataBeltRealign* pDevData, QString& sErrMsg);
	bool addCorrectPoint(QString sPointGuid, QString sPointName, QString PlcIP, int nPlcPort, QString sCamerIP, int nCamerPort,
		QString sCamerUser, QString sPassWd, int nIsHavePlc, int nSetValue, int nSetValueTwo, int nAlarmTime, QString sPicPath, int nIsHaveBeltState, double dLeftRaito,
		double dRightRatio, QString sBeltName, QString sRtsp, QString& sErrMsg);
	bool updateCorrectPoint(QString sPointGuid, QString sPointName, QString PlcIP, int nPlcPort,
		QString sCamerIP, int nCamerPort, QString sCamerUser, QString sPassWd, int nIsHavePlc, int nSetValue, int nSetValueTwo, int nAlarmTime, QString sPicPath,
		int nIsHaveBeltState, double dLeftRaito, double dRightRatio, QString sBeltName, QString sRtsp, QString& sErrMsg);
	bool insertCorrectPoint(QString sPointGuid, QString sPointName, QString PlcIP, int nPlcPort,
		QString sCamerIP, int nCamerPort, QString sCamerUser, QString sPassWd, int nIsHavePlc, int nSetValue, int nSetValueTwo, int nAlarmTime, QString sPicPath,
		int nIsHaveBeltState, double dLeftRaito, double dRightRatio, QString sBeltName, QString sRtsp, QString& sErrMsg);
	bool deleteCorrectPoint(QString sPointGuid, QString& sErrMsg);
	bool selectAllocationTable(QString sPointGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
	bool addRobModbus(QString sRobGuid, QList<QStringList> listModbusData, QString& sErrMsg);
	bool deleteAllocationTable(QString sPointGuid, QString& sErrMsg);
	bool selectBeltWork(QVector<QSqlRecord>& vecDataInfo, QString& sErrMsg);
	bool selectBeltCorrect(QString sPointGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
	bool selectTagConfig(QString& sPointGuid,CDevDataBeltRealign* pDevData, QString& sErrMsg);
	bool selectTagID(QString& sPointGuid, QString& sTagID, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
	bool insertTagID(QString& sPointGuid, QString& sTagID, QString& sTagAddr, QString& sErrMsg);
	bool updateTagID(QString& sPointGuid, QString& sTagID, QString& sTagAddr, QString& sErrMsg);
	bool selectDevInfo(QString& sDevGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
	bool insertDevInfo(QString& sDevGuid, QString& sDevName,QString& sPointGuid, QString& sErrMsg);
	//添加跑偏结果
	bool addCorrectResult(QString sReusltGuid, QString sPointGuid, QString sPointName, double dLeftValue, double dRightValue, QDateTime dStartTime, QString PicUrl,
		QString sHttpUrl, QString AlarmDesc, QString sBeltName, int nAlarmType, int nRealignSetValue, int nRealignSetValueTwo, QString& sErrMsg);
	//更新跑偏结束时间
	bool updateCorrectStopTime(QString sResultGuid, double dAvgLeftValue, double dAvgRight, QString& sErrMsg);

	bool selectResultLastTime(QVector<QSqlRecord>& vecRecord, QString sErrMsg);
	bool selectRecRetInfo(QVector<QSqlRecord>& vecRecord, QString sStartTime, QString sEndTime, QString& sErrMsg);
	bool insertResult(QString sGuid, int nResultType, QString sResultName, QDateTime dTime, QString sPath, QString sHttpUrl, QString& sErrMsg);
	bool selectResult(QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecInfo, QString& sErrMsg);
	bool deleteDevInfo(QString sDevId, QString& sErrMsg);
	bool deleteCamerInfo(QString sDevGuid, QString& sErrMsg);

private:
	CSqlOper();
	~CSqlOper();

	CSqlDllOper* m_pDbDllOper;
};

#endif // 